var v = null;
var vid = -1;
chrome.windows.onRemoved.addListener(function(windowId) {
	if(windowId==vid)
	{
		vid=-1;
		console.log("closed!");
	}
});
chrome.browserAction.onClicked.addListener(function(tab) {
 // chrome.windows.getAll({}, function(window_list) {
      // check if already exists 
	 
	//  $.each(window_list,function(entryIndex,entry){
		//w=entry; 

			console.log(vid);
			if(vid==-1)
			{
					//Ori_ReplayWindow=entry.id;
					//ReplayWindow=entry.id;
					//Initialize();
					//console.log(Ori_ReplayWindow);
				chrome.windows.create({'url': './popup.html','width':575,'height':900, 'type': 'panel', 'focused': true},function(v){vid=v.id;console.log(vid);});
				vid=1;
			
			}
			else
			{
			  chrome.windows.update(vid, {'focused':true}, function(){});
			}
		//});
	  
	 // });
	  /*
	  chrome.windows.getCurrent({'populate':false}, function(win){
			Ori_ReplayWindow=win.id;
			ReplayWindow=win.id;
	   });
	   chrome.tabs.getCurrent(function(t){
			Ori_ReplayTab=t.id;
			ReplayTab=t.id;
	   });
	   console.log(ReplayWindow);
	   console.log(ReplayTab);
	   */
	   
   
  });